#!/bin/sh

# 服务自动启动脚本
# 在用户目录下面 添加 crontab -e 
# */1     *       *       *       *       . ~/.bash_profile ;[脚本文件名]
# /bin/systemctl restart crond.service

ROOTDIR=`pwd`
PROCESS_DIR=/home/telemrcp/telemrcpsvr
#PROCESS_DIR=/home/wurong/Desktop/study-cpp/apr-learning
PROCESS_BIN_DIR=${PROCESS_DIR}/bin
PROCESS=unimrcpserver

start_server(){
    cd ${PROCESS_BIN_DIR}
    nohup ./${PROCESS} > /dev/null 2>&1 &
    echo "loading..."
    sleep 1
    tmp=`ps -A | grep ${PROCESS} | wc -l`
    if [ $tmp -eq 0 ] ;then

        echo "${PROCESS} is stop"
    else 
        echo "${PROCESS} is running"
    fi

    cd ${ROOTDIR}
}
Tmp1=`ps -A | grep ${PROCESS} | wc -l`
if [ $Tmp1 -eq 0 ] #没有启动
then
    start_server
else
    echo "${PROCESS} is running now"
fi


